Skip to main content

Public Key Encryption

Public Key Encryption, also called Asymmetric Encryption, is a cryptographic system that uses two different keys:

  • A public key (shared openly)
  • A private key (kept secret)

Data encrypted with one key can only be decrypted with the other.

This allows for secure data transmission between parties without sharing a secret key in advance, and is essential for:

  • Authentication
  • Secure communication
  • Digital signatures

Key Concepts of Public Key Encryption

ConceptDescription
Public KeyUsed to encrypt data; can be shared openly
Private KeyUsed to decrypt data; must be kept secret
AsymmetricDifferent keys for encryption and decryption
One-way encryptionYou can encrypt with the public key, but only decrypt with the private key
Digital SignatureCreated by encrypting a hash with the private key to verify authenticity

Common Algorithm of Public Key Encryption

AlgorithmUse
RSA (Rivest–Shamir–Adleman)Most common, used for encryption and digital signatures
ECC (Elliptic Curve Cryptography)Lighter and faster alternative to RSA, used in modern systems
ElGamalLess common, but also used in secure messaging

Where Public Key Encryption is used

Use CaseDescription
TLS/HTTPSPublic/private keys establish secure connections between clients and servers
AuthenticationPrivate key signs a token; public key verifies it (e.g., JWT, OAuth)
Secure Key ExchangeUsed to share symmetric keys securely (e.g., in hybrid encryption)
Data ProtectionEncrypt sensitive data for a specific recipient
Email EncryptionPGP/GPG uses public key crypto to secure messages

Example of Public Key Encryption

Scenario: A client (browser or app) connects to a backend server using HTTPS. We want to ensure:

  • The server is authentic (not a fake)
  • Data is encrypted during transmission

TLS Handshake Using Public Key Encryption

  1. Server has a public/private key pair
    • Public key is included in its SSL certificate (issued by a Certificate Authority)
  2. Client initiates connection
    • Requests server's public key (via the certificate)
  3. Client encrypts a random symmetric key with the server’s public key
  4. Server decrypts it using its private key
  5. Both now use the symmetric key to encrypt the session (fast and secure)

Security Benefits of Public Key Encryption

BenefitExplanation
No shared secret requiredSafer for open networks
Identity verificationPrivate key signatures prove authenticity
Hybrid encryption supportWorks with symmetric encryption for speed and security
Widely trustedForms the backbone of HTTPS, SSH, and JWTs